//
//  MultiSelectionCellData.m
//  18Birdies
//
//  Created by Lc on 15/5/14.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import "LcFoundation.h"
#import "MultiSelectionCell.h"
#import "MultiSelectionCellData.h"

@implementation MultiSelectionCellData

+ (MultiSelectionCellData*)cellDataWithTitle:(NSString*)title
                                    selected:(BOOL)selected {
  LC_CHECK_NOT_EMPTY(title);
  return [self cellDataWithTitle:title rightButtonTitle:nil selected:selected];
}

+ (MultiSelectionCellData*)cellDataWithTitle:(NSString*)title
                            rightButtonTitle:(NSString*)rightButtonTitle
                                    selected:(BOOL)selected {
  LC_CHECK_NOT_EMPTY(title);
  MultiSelectionCellData* cellData = [[self alloc] init];
  cellData->_title = title.copy;
  cellData.rightButtonTitle = rightButtonTitle;
  cellData.selected = selected;
  cellData.clickable = YES;
  cellData.cellHeight = 44;
  return cellData;
}

- (Class)cellClazz {
  return MultiSelectionCell.class;
}

- (NSString*)nibName {
  return @"MultiSelectionCell";
}

- (void)refreshCell:(MultiSelectionCell*)cell {
  [super refreshCell:cell];
  
  if (_backgroundColor != nil) {
    cell.backgroundColor = _backgroundColor;
  }
  
  cell.checkerImageView.image = self.selected
                                    ? [UIImage imageNamed:@"choice_active"]
                                    : [UIImage imageNamed:@"choice_normal"];
  if (self.titleFont != nil) {
    [cell.titleLabel setLcFont:self.titleFont];
  } else {
    [cell.titleLabel setLcFont:[LcFont dr17]];
  }
  cell.titleLabel.text = self.title;
  if (self.rightButtonTitle.length == 0) {
    cell.rightArrow.hidden = YES;
    cell.rightButton.hidden = YES;
  } else {
    cell.rightArrow.hidden = NO;
    cell.rightButton.hidden = NO;
    [cell.rightButton setTitle:self.rightButtonTitle
                      forState:UIControlStateNormal];
    [cell.rightButton setTitleColor:self.selected ? LC_COLOR_BLUE
                                                  : LC_COLOR_BLACKGROUND_GRAY
                           forState:UIControlStateNormal];
    cell.rightButton.enabled = self.selected;
  }
}

@end
